/**
 * 
 */
package pt.iscteiul.worldfootball.businesslayer;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author Rafael Campos
 * 
 */
public class CalendarDateTest {

	private static CalendarDate calendarDate;
	private static CalendarDate anotherCalendarDate;

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		calendarDate = new CalendarDate();
		anotherCalendarDate = new CalendarDate();
		
		calendarDate.init(5, 1, 1991);
		anotherCalendarDate.init(5, 1, 2000);

	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		calendarDate = null;
		anotherCalendarDate = null;
	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#init(int, int, int)}
	 * .
	 */
	@Test
	public void testInit() {
		assertEquals(5, calendarDate.day());
		assertEquals(1, calendarDate.month());
		assertEquals(1991, calendarDate.year());
	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#initS(java.lang.String)}
	 * .
	 */
	@Test
	public void testInitS() {
		calendarDate.initS("2001-04-21");
		assertEquals(21, calendarDate.day());
		assertEquals(4, calendarDate.month());
		assertEquals(2001, calendarDate.year());
	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#isAfter(pt.iscteiul.worldfootball.businesslayer.CalendarDate)}
	 * .
	 */
	@Test
	public void testIsAfter() {
		assertTrue(calendarDate.isAfter(new CalendarDate(4, 1, 1991)));
		assertFalse(calendarDate.isAfter(new CalendarDate(6, 1, 1991)));
		assertFalse(calendarDate.isAfter(new CalendarDate(6, 1, 1992)));
		assertFalse(calendarDate.isAfter(new CalendarDate(6, 2, 1991)));
		assertTrue(calendarDate.isAfter(new CalendarDate(4, 1, 1990)));

	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#isBefore(pt.iscteiul.worldfootball.businesslayer.CalendarDate)}
	 * .
	 */
	@Test
	public void testIsBefore() {
		assertTrue(calendarDate.isBefore(new CalendarDate(6, 1, 1991)));
		assertFalse(calendarDate.isBefore(new CalendarDate(4, 1, 1991)));

	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#isDivisible(int, int)}
	 * .
	 */
	@Test
	public void testIsDivisible() {
		assertTrue(calendarDate.isDivisible(6, 3));
		assertFalse(calendarDate.isDivisible(5, 3));

	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#isEqual(pt.iscteiul.worldfootball.businesslayer.CalendarDate)}
	 * .
	 */
	@Test
	public void testIsEqual() {
		assertTrue(calendarDate.isEqual(new CalendarDate(5, 1, 1991)));
		assertFalse(calendarDate.isEqual(new CalendarDate(6, 1, 1991)));

	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#isLeap()}.
	 */
	@Test
	public void testIsLeap() {
		CalendarDate calendarDate2 = calendarDate.stringToDate("2300-04-21");

		assertFalse(calendarDate.isLeap());
		assertTrue(anotherCalendarDate.isLeap());
		assertFalse(calendarDate2.isLeap());
	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#stringToDate(java.lang.String)}
	 * .
	 */
	@Test
	public void testStringToDate() {
		CalendarDate calendarDate2 = calendarDate.stringToDate("2001-04-21");
		assertEquals(21, calendarDate2.day());
		assertEquals(4, calendarDate2.month());
		assertEquals(2001, calendarDate2.year());
	}

	/**
	 * Test method for
	 * {@link pt.iscteiul.worldfootball.businesslayer.CalendarDate#yearsSince(pt.iscteiul.worldfootball.businesslayer.CalendarDate)}
	 * .
	 */
	@Test
	public void testYearsSince() {
		assertEquals(9, anotherCalendarDate.yearsSince(calendarDate));

		CalendarDate calendarDate2 = calendarDate.stringToDate("1989-04-21");

		assertEquals(1, calendarDate.yearsSince(calendarDate2));
		}

}
